/*  

Cafechess Library: Cover basic chess programming needs, like GUI, Engine integration, 
FEN and PGN parsing.

                 \\|//
                 (o o)
--------------ooO-(_)-Ooo----------------------------------
Copyright (C) 2009  By Gregory A. Prentice Snoqualmie, WA
                    www.cafechess.org
                    cafechess@comcast.net
                      Oooo
--------------oooO----(  )---------------------------------
              (  )    (_/
               \_)

Microsoft Public License (Ms-PL)
 
Revisions:

Author        Date    Description:

*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Cafechess.Forms
{
  abstract public class UpdateThreaded
  {
    protected Control coControl;
    /// <summary>
    /// Definition of delegate used for updating the UI.
    /// </summary>
    private delegate void UpdateUserInterface();
    /// <summary>
    /// Declare our Delegate
    /// </summary>
    UpdateUserInterface coUiUpdate;
    UpdateUserInterface coUiReset;
    public UpdateThreaded(Control control)
    {
      coControl = control;
      coUiUpdate = new UpdateUserInterface(UpdateUI);
      coUiReset = new UpdateUserInterface(ResetUI);
    }

    public void Reset()
    {
      if (coControl.InvokeRequired)
        coControl.Invoke(coUiReset);
      else
        ResetUI();
    }

    public void Update()
    {
      if (coControl.InvokeRequired)
        coControl.Invoke(coUiUpdate);
      else
        UpdateUI();
    }
    /// <summary>
    /// Implement this function to perform the actual updates of the user interfaces.
    /// It is consider safe to update the controls while in the routine directly.
    /// </summary>
    protected abstract void UpdateUI();
    protected abstract void ResetUI();

  }
}
